//
//  HotView.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/4.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "HotView.h"
#import "ShoppingHotContentTableViewCell.h"
#import "StockGoodsContentViewController.h"

#import "MoreGoodsShowViewController.h"
#import "FilterViewController.h"
#import "SideSlipCommonTableViewCell.h"

#import "CommonItemModel.h"
#import "SupportCategoryGoodListModel.h"


static NSString *hotGoodsCellID = @"hotGoodsCell";

@interface HotView () <UITableViewDelegate, UITableViewDataSource>

@property (strong, nonatomic) UIView *headerV;
@property (strong, nonatomic) UIImageView *leftIV;
@property (strong, nonatomic) UIImageView *rightIV;
@property (strong, nonatomic) UILabel *headerTitle;
@property (strong, nonatomic) UILabel *desL;

@property (strong, nonatomic) UIView *bg;
@property (strong, nonatomic) UIView *headerView;
@property (strong, nonatomic) UITableView *hotGoodsTableView;
@property (strong, nonatomic) UIView *loadMoreView;
@property (strong, nonatomic) UIImageView *smallBackIV;
@property (strong, nonatomic) UILabel *loadMoreL;

// 用于标记在价格是选中状态下，显示不同的图片  YES 表示价格升序  NO表示价格降序
@property (assign, nonatomic) BOOL priceIsSelected;

@property (strong, nonatomic) UIButton *selectedBtn;

//@property (strong, nonatomic) NSArray *dataArr;

@property (assign, nonatomic) NSInteger controllerType;

@property (assign, nonatomic) BOOL number;

@property (assign, nonatomic) NSInteger page;


@property (copy, nonatomic) NSString *classID;

@end

@implementation HotView

- (instancetype)initWithTitle:(NSString *)title andDes:(NSString *)desl controllerType:(NSInteger)type {
    
    self = [super init];
    
    if (self) {
        
//        self.page = 1;
        self.number = NO;
 
        self.controllerType = type;
        
        self.headerTitle.text = title;
        self.desL.text = desl;
        
        self.layer.cornerRadius = jisuan(10);
        self.layer.masksToBounds = YES;
        
        self.backgroundColor = WhiteColor;

        [self addSubview:self.headerV];
        [self.headerV addSubview:self.leftIV];
        [self.headerV addSubview:self.rightIV];
        [self.headerV addSubview:self.headerTitle];
        [self.headerV addSubview:self.desL];
        
        [self addSubview:self.bg];
        [self.bg addSubview:self.headerView];
        [self.bg addSubview:self.hotGoodsTableView];
        [self.bg addSubview:self.loadMoreView];
        [self.loadMoreView addSubview:self.smallBackIV];
        [self.loadMoreView addSubview:self.loadMoreL];
        
        if (type == 1) {
            
            self.loadMoreView.hidden = YES;
            self.loadMoreL.hidden = YES;
            
            self.hotGoodsTableView.bounces = NO;
            self.hotGoodsTableView.scrollEnabled = NO;
            
//            MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
//
//            // 设置文字
//            [footer setTitle:@"点击加载更多" forState:MJRefreshStateIdle];
//            [footer setTitle:@"正在加载" forState:MJRefreshStateRefreshing];
//            [footer setTitle:@"没有更多数据" forState:MJRefreshStateNoMoreData];
//
//            // 设置字体
//            footer.stateLabel.font = Font(17);
//
//            // 设置颜色
//            footer.stateLabel.textColor = Color999999;
//
//            // 设置footer
//            self.hotGoodsTableView.mj_footer = footer;
        
        }
        
//        [self loadData];
        [self createWithtitle:@"综合" image:nil withTag:0];
        [self createWithtitle:@"销量" image:nil withTag:1];
        [self createWithtitle:@"价格" image:[UIImage imageNamed:@"priceNormal"] withTag:2];
        [self createWithtitle:@"优惠" image:nil withTag:3];
        
    }

    return self;
}


- (void)setGoodListArr:(NSMutableArray *)goodListArr {
    
    _goodListArr = goodListArr;
    
    [self.hotGoodsTableView reloadData];
}

//- (void)loadMoreData {
//
//    self.page ++;
//
//    [self getDataWithClassID:self.classID];
//
//    [self.hotGoodsTableView reloadData];
//
//    // 拿到当前的上拉刷新控件，结束刷新状态
//    [self.hotGoodsTableView.mj_footer endRefreshing];
//
//}

//- (void)getDataWithClassID:(NSString *)classID {
//    
//    self.classID = classID;
//     
//    __weak typeof(self) weakSelf = self;
//    
//    [SupportCategoryGoodListModel supprotGoodListWithPage:self.page andClassID:classID successBlock:^(id responseObject) {
//        
//        NSLog(@"%@",responseObject);
//        
//        if ([responseObject[@"code"] integerValue] == 1) {
//            
//            NSArray *arr = responseObject[@"data"];
//            
//            if (arr.count > 0 || weakSelf.goodListArr.count > 0 ) {
//                
//                weakSelf.hotGoodsTableView.hidden = NO;
//                
//                if (self.page == 1) {
//                    
//                    weakSelf.goodListArr = (NSMutableArray *)arr;
//                    
//                }else {
//                    
//                    [weakSelf.goodListArr addObjectsFromArray:arr];
//                    
//                }
//                
//                CGFloat height = 0;
//                int num = (int)self.goodListArr.count;
//                
//                if (self.goodListArr.count == 0) {
//                    
//                    //        height = num * jisuan(225) + jisuan(160);
//                    
//                    height = num * jisuan(225);
//                    
//                }else {
//                    
//                    //            height = (num + 1) * jisuan(225) + jisuan(200);
//                    
//                    height = num * jisuan(225) + jisuan(260);
//                    
//                }
//                
//                CGSize size = CGSizeMake(WIDTH, height);
//
//                if (self.sizeBlock) {
//                    
//                    self.sizeBlock(size);
//                    
//                }
//
//                [weakSelf.hotGoodsTableView reloadData];
//                
//                if (self.page > 1 && arr.count == 0) {
//                    
//                    [self.hotGoodsTableView.mj_footer endRefreshingWithNoMoreData];
//                }
//                
//                // 滚动cell
//                NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:(self.page - 1) * 10];
//                
////                [weakSelf.goodsCotllectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];
//                    [weakSelf.hotGoodsTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
//            }else {
//                
//                weakSelf.hotGoodsTableView.hidden = YES;
//                //                weakSelf.tipView.hidden = NO;
//                
//                //                weakSelf.tipView = [[TipView alloc] initWithImage:@"wujilu2" andText:@"暂无奖励" showButton:NO andBtnAction:nil];
//                //                weakSelf.tipView.frame = self.view.bounds;
//                
//                //                [weakSelf.view addSubview:weakSelf.tipView];
//           
//            }
//            
//        }else {
//            
//            [[KYAlertView sharedInstance] showAlertViewWithMessage:responseObject[@"msg"]];
//            
//            [self.hotGoodsTableView reloadData];
//        }
//        
//    } failBlock:^(NSError *error) {
//        
//        if (error) {
//            
//            [[KYAlertView sharedInstance] showAlertViewWithMessage:Tip];
//        }
//        
//    }];
//    
//}

#pragma mark -分栏按钮点击事件
- (void)btnClick:(UIButton *)btn {
    
    
    if (btn!= self.selectedBtn) {
        
        self.selectedBtn.selected = NO;

        btn.selected = YES;
        self.selectedBtn = btn;
        
    }else{

        if (btn.tag == 0 || btn.tag == 1 || btn.tag == 3) {
            
            return;
        
        }
        
    }

    if (btn.tag == 0) {
        
        NSLog(@"综合");
        self.priceIsSelected = YES;
        
        // 综合数据请求
        if (self.hotViewClickBlock) {
            self.hotViewClickBlock(1);
        }
        

    }else if (btn.tag == 1) {
        
        NSLog(@"销量");
        self.priceIsSelected = YES;
        
        // 销量数据请求
        if (self.hotViewClickBlock) {
            self.hotViewClickBlock(2);
        }
        
    }else if (btn.tag == 2) {
        
        if (self.priceIsSelected) {
            
            NSLog(@"升序");
            
            [btn setImage:[UIImage imageNamed:@"priceUp"] forState:UIControlStateSelected];
            
            self.priceIsSelected = NO;
            
            // 价格升序数据请求
            if (self.hotViewClickBlock) {
                self.hotViewClickBlock(3);
            }
            
        }else {
            
            NSLog(@"降序");
            
            [btn setImage:[UIImage imageNamed:@"priceDown"] forState:UIControlStateSelected];
            
            self.priceIsSelected = YES;
            
            // 价格降序数据请求
            if (self.hotViewClickBlock) {
                self.hotViewClickBlock(4);
            }
            
        }
        
        
    }else  {
        
        NSLog(@"筛选");
        self.priceIsSelected = YES;
        
        
        if (!self.number) {
            
//            FilterViewController *filterVC = [[FilterViewController alloc] initWithSponsor:self.parentVC withCommitBlock:^(NSMutableString *commitStr) {
//                
//                NSLog(@"commitStr: %@", commitStr);
//                
//            } withViewDimissBlock:^(BOOL isDimiss) {
//                
//                self.number = isDimiss;
//                
//            }];
//            
//            filterVC.dataList = [self packageDataList];
//            [filterVC show];
//            
//            self.number = YES;
            
        }
        
        // 筛选数据请求
        
        if (self.hotViewClickBlock) {
            self.hotViewClickBlock(5);
        }

    }
    
    
    
}

#pragma mark - 模拟数据源
- (NSArray *)packageDataList {
    
    NSMutableArray *dataArray = [NSMutableArray array];
    
    [dataArray addObject:[self serviceFilterRegionModel]];
    [dataArray addObject:[self priceFilterRegionModel]];
    [dataArray addObject:[self commonFilterRegionModelWithKeyword:@"品牌" selectionType:BrandTableViewCellSelectionTypeMultiple]];
    [dataArray addObject:[self commonFilterRegionModelWithKeyword:@"尺码" selectionType:BrandTableViewCellSelectionTypeSingle]];
    [dataArray addObject:[self commonFilterRegionModelWithKeyword:@"适用群体" selectionType:BrandTableViewCellSelectionTypeMultiple]];
    [dataArray addObject:[self commonFilterRegionModelWithKeyword:@"鞋帮高度" selectionType:BrandTableViewCellSelectionTypeMultiple]];
    [dataArray addObject:[self commonFilterRegionModelWithKeyword:@"重量" selectionType:BrandTableViewCellSelectionTypeMultiple]];


    return [dataArray mutableCopy];
}


- (ZYSideSlipFilterRegionModel *)commonFilterRegionModelWithKeyword:(NSString *)keyword selectionType:(CommonTableViewCellSelectionType)selectionType {
    ZYSideSlipFilterRegionModel *model = [[ZYSideSlipFilterRegionModel alloc] init];
    model.containerCellClass = @"SideSlipCommonTableViewCell";
    model.regionTitle = keyword;
    model.customDict = @{REGION_SELECTION_TYPE:@(selectionType)};
    model.itemList = @[[self createItemModelWithTitle:[NSString stringWithFormat:@"%@一", keyword] itemId:@"0000" selected:NO],
                       [self createItemModelWithTitle:[NSString stringWithFormat:@"%@二", keyword] itemId:@"0001" selected:NO],
                       [self createItemModelWithTitle:[NSString stringWithFormat:@"%@三", keyword] itemId:@"0002" selected:NO],
                       [self createItemModelWithTitle:[NSString stringWithFormat:@"%@四", keyword] itemId:@"0003" selected:NO],
                       [self createItemModelWithTitle:[NSString stringWithFormat:@"%@五", keyword] itemId:@"0004" selected:NO],
                       [self createItemModelWithTitle:[NSString stringWithFormat:@"%@六", keyword] itemId:@"0005" selected:NO],
                       [self createItemModelWithTitle:[NSString stringWithFormat:@"%@七", keyword] itemId:@"0006" selected:NO],
                       [self createItemModelWithTitle:[NSString stringWithFormat:@"%@八", keyword] itemId:@"0007" selected:NO],
                       [self createItemModelWithTitle:[NSString stringWithFormat:@"%@九", keyword] itemId:@"0008" selected:NO],
                       [self createItemModelWithTitle:[NSString stringWithFormat:@"%@十", keyword] itemId:@"0009" selected:NO]
                       ];
    return model;
}

#pragma mark -来源
- (ZYSideSlipFilterRegionModel *)serviceFilterRegionModel {
    ZYSideSlipFilterRegionModel *model = [[ZYSideSlipFilterRegionModel alloc] init];
    model.containerCellClass = @"SideSlipSourceTableViewCell";
    model.regionTitle = @"来源";
    model.itemList = @[[self createItemModelWithTitle:@"爱淘帮" itemId:@"0000" selected:NO],
                       [self createItemModelWithTitle:@"淘宝" itemId:@"0001" selected:NO],
                       [self createItemModelWithTitle:@"天猫" itemId:@"0002" selected:NO],
                       [self createItemModelWithTitle:@"京东" itemId:@"0003" selected:NO],
                       ];
//    model.customDict = @{ADDRESS_LIST:[self generateAddressDataList]};
    return model;
}
#pragma mark -价格
- (ZYSideSlipFilterRegionModel *)priceFilterRegionModel {
    ZYSideSlipFilterRegionModel *model = [[ZYSideSlipFilterRegionModel alloc] init];
    model.containerCellClass = @"SideSlipPriceTableViewCell";
    model.regionTitle = @"价格";
    return model;
}

- (CommonItemModel *)createItemModelWithTitle:(NSString *)itemTitle
                                       itemId:(NSString *)itemId
                                     selected:(BOOL)selected {
    CommonItemModel *model = [[CommonItemModel alloc] init];
    model.itemId = itemId;
    model.itemName = itemTitle;
    model.selected = selected;
    return model;

}

#pragma mark -更多商品点击事件
- (void)loadMoreGestureClick:(UIGestureRecognizer *)recognizer {
    
    NSLog(@"更多商品点击事件");
    
    if (self.controllerType == 0) {
        
        if (self.supportType == 0) {
            
            NSLog(@"购物===自营====更多商品点击事件");
            
            
        }else {
            
            NSLog(@"购物===非自营====更多商品点击事件");
            
        }
        
        MoreGoodsShowViewController *goodsVC = [[MoreGoodsShowViewController alloc] init];
        goodsVC.title = @"热销商品";
//        goodsVC.isSelfSupport = self.isSelfSupport;
        goodsVC.supportType = self.supportType;
        [self.parentVC.navigationController pushViewController:goodsVC animated:YES];
        
    }else {
        
        if (self.supportType == 0) {
            
            NSLog(@"进货====自营====更多商品点击事件");
            
        }else {
            
            NSLog(@"进货====非自营====更多商品点击事件");
            
        }
        
        MoreGoodsShowViewController *goodsVC = [[MoreGoodsShowViewController alloc] init];
        goodsVC.title = @"热销推荐商品";
//        goodsVC.isSelfSupport = self.isSelfSupport;
        goodsVC.supportType = self.supportType;
        [self.parentVC.navigationController pushViewController:goodsVC animated:YES];
    }
    
    
//    if (self.controllerType == 0) {
//
//        if (self.isSelfSupport) {
//
//            NSLog(@"购物===自营====更多商品点击事件");
//
//
//        }else {
//
//            NSLog(@"购物===非自营====更多商品点击事件");
//
//        }
//
//        MoreGoodsShowViewController *goodsVC = [[MoreGoodsShowViewController alloc] init];
//        goodsVC.title = @"热销商品";
//        goodsVC.isSelfSupport = self.isSelfSupport;
//        [self.parentVC.navigationController pushViewController:goodsVC animated:YES];
//
//    }else {
//
//        if (self.isSelfSupport) {
//
//            NSLog(@"进货====自营====更多商品点击事件");
//
//        }else {
//
//            NSLog(@"进货====非自营====更多商品点击事件");
//
//        }
//
//        MoreGoodsShowViewController *goodsVC = [[MoreGoodsShowViewController alloc] init];
//        goodsVC.title = @"热销推荐商品";
//        goodsVC.isSelfSupport = self.isSelfSupport;
//        [self.parentVC.navigationController pushViewController:goodsVC animated:YES];
//    }
//
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
//    return jisuan(225);
    return jisuan(205);
    
}


#pragma mark -delegate、datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    // 进货
    if (self.controllerType == 1) {
        
        return self.goodListArr.count;
        
    }else {
        
        return 4;
        
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    ShoppingHotContentTableViewCell *cell = [[ShoppingHotContentTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:hotGoodsCellID];

    if (self.controllerType == 1) {
        
        // 自营
        cell.type = 1;
        
        cell.model = self.goodListArr[indexPath.row];
        
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSLog(@"热销商品点击事件");
    
    if (self.controllerType == 0) {
        
        if (self.supportType == 0) {
            
            NSLog(@"购物===自营====热销商品点击事件");
            ShoppingGoodsContentViewController *vc = [[ShoppingGoodsContentViewController alloc] init];
            [self.parentVC.navigationController pushViewController:vc animated:YES];
            
        }else {
            
            NSLog(@"购物===非自营====热销商品点击事件");
            
            // 优先拉起手淘：@"taobao_scheme" \\\ 天猫：tmall_scheme
            [CommonAction sharedInstance].linkType = @"taobao_scheme";

            [[CommonAction sharedInstance] goToTbGoodsDetailWith:self.parentVC itemDetailPage:@"41576306115"];
            
        }
        
    }else {
        
        //        if (self.isSelfSupport) {
        //
        //            NSLog(@"进货====自营====热销商品点击事件");
        //
        //        }else {
        //
        //            NSLog(@"进货====非自营====热销商品点击事件");
        //
        //        }
        
        
        ShoppingGoodsContentViewController *vc = [[ShoppingGoodsContentViewController alloc] init];
        
        SupportCategoryGoodListModel *model = self.goodListArr[indexPath.row];
        vc.goodID = model.goodId;
        
        [self.parentVC.navigationController pushViewController:vc animated:YES];
        
//        StockGoodsContentViewController *vc = [[StockGoodsContentViewController alloc] init];
//        [self.parentVC.navigationController pushViewController:vc animated:YES];
        
        
    }

//    if (self.controllerType == 0) {
//
//        if (self.isSelfSupport) {
//
//            NSLog(@"购物===自营====热销商品点击事件");
//            ShoppingGoodsContentViewController *vc = [[ShoppingGoodsContentViewController alloc] init];
//            [self.parentVC.navigationController pushViewController:vc animated:YES];
//
//        }else {
//
//            NSLog(@"购物===非自营====热销商品点击事件");
//
//        }
//
//    }else {
//
////        if (self.isSelfSupport) {
////
////            NSLog(@"进货====自营====热销商品点击事件");
////
////        }else {
////
////            NSLog(@"进货====非自营====热销商品点击事件");
////
////        }
//
//        StockGoodsContentViewController *vc = [[StockGoodsContentViewController alloc] init];
//        [self.parentVC.navigationController pushViewController:vc animated:YES];
//
//
//    }
    
}


- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    [self.headerV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.mas_left);
        make.right.mas_equalTo(weakSelf.mas_right);
        make.top.mas_equalTo(weakSelf.mas_top);
        make.height.mas_equalTo(jisuan(140));
    }];
    [self.headerTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(weakSelf.headerV.mas_centerX);
        make.top.mas_equalTo(weakSelf.headerV.mas_top).with.offset(jisuan(38));
        
    }];
    [self.leftIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(weakSelf.headerTitle.mas_centerY);
        make.right.mas_equalTo(weakSelf.headerTitle.mas_left).with.offset(-SmallMargin);
        make.width.mas_equalTo(jisuan(30));
        make.height.mas_equalTo(jisuan(24));
    }];
    [self.rightIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(weakSelf.headerTitle.mas_centerY);
        make.left.mas_equalTo(weakSelf.headerTitle.mas_right).with.offset(SmallMargin);
        make.width.mas_equalTo(jisuan(30));
        make.height.mas_equalTo(jisuan(24));
    }];
    [self.desL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(weakSelf.headerV.mas_centerX);
        make.bottom.mas_equalTo(weakSelf.headerV.mas_bottom).with.offset(-jisuan(30));
    
    }];
    
    [self.bg mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.mas_left);
        make.right.mas_equalTo(weakSelf.mas_right);
        make.top.mas_equalTo(weakSelf.headerV.mas_bottom);
        make.bottom.mas_equalTo(weakSelf.mas_bottom);
//        make.height.mas_equalTo(jisuanH(1020));
    }];
    
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.bg.mas_left);
        make.right.mas_equalTo(weakSelf.bg.mas_right);
        make.top.mas_equalTo(weakSelf.bg.mas_top);
        make.height.mas_equalTo(jisuanH(60));
        
    }];
    
//    [self.hotGoodsTableView mas_makeConstraints:^(MASConstraintMaker *make) {
//
//        make.left.mas_equalTo(weakSelf.bg.mas_left);
//        make.right.mas_equalTo(weakSelf.bg.mas_right);
//        make.top.mas_equalTo(weakSelf.headerView.mas_bottom).with.offset(jisuan(1));
//        make.bottom.mas_equalTo(weakSelf.bg.mas_bottom).with.offset(-jisuan(61));
//
//    }];

    if (self.controllerType == 1) {
        
        self.loadMoreView.hidden = YES;
        self.loadMoreL.hidden = YES;
        self.smallBackIV.hidden = YES;
        
        [self.hotGoodsTableView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(weakSelf.bg.mas_left);
            make.right.mas_equalTo(weakSelf.bg.mas_right);
            make.top.mas_equalTo(weakSelf.headerView.mas_bottom).with.offset(jisuan(1));
            make.bottom.mas_equalTo(weakSelf.bg.mas_bottom);
            
        }];
        
    }else {
        
        [self.hotGoodsTableView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(weakSelf.bg.mas_left);
            make.right.mas_equalTo(weakSelf.bg.mas_right);
            make.top.mas_equalTo(weakSelf.headerView.mas_bottom).with.offset(jisuan(1));
            make.bottom.mas_equalTo(weakSelf.bg.mas_bottom).with.offset(-jisuan(61));
            
        }];
        
        [self.loadMoreView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(weakSelf.bg.mas_left);
            make.right.mas_equalTo(weakSelf.bg.mas_right);
            make.bottom.mas_equalTo(weakSelf.bg.mas_bottom);
                    make.height.mas_equalTo(jisuan(60));
//            make.top.mas_equalTo(weakSelf.hotGoodsTableView.mas_bottom);
            
        }];
        
        [self.loadMoreL mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.centerY.mas_equalTo(weakSelf.loadMoreView.mas_centerY);
            make.centerX.mas_equalTo(weakSelf.loadMoreView.mas_centerX).with.offset(-jisuan(10));
            
        }];
        [self.smallBackIV mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(weakSelf.loadMoreL.mas_right).with.offset(jisuan(10));
            make.centerY.mas_equalTo(weakSelf.loadMoreView.mas_centerY);
            make.width.mas_equalTo(jisuan(11));
            make.height.mas_equalTo(jisuan(20));
        }];
        
    }
    
   
    
}

- (void)createWithtitle:(NSString *)name image:(UIImage *)image withTag:(NSInteger)tag {
    
    UIButton *btn = [[UIButton alloc] init];
    btn.titleLabel.font = Font(24);
    btn.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [btn setTitle:name forState:UIControlStateNormal];
    [btn setTitleColor:Color333333 forState:UIControlStateNormal];
    [btn setTitleColor:Colorff0000 forState:UIControlStateSelected];
//    [btn setTitleColor:Colorff0000 forState:UIControlStateDisabled];
    
    btn.tag = tag;
    
    CGFloat width = jisuan(80);
    CGFloat margin = (WIDTH - SmallMargin * 2 - Margin * 2 - width * 4) / 3.0;
    CGFloat x = SmallMargin + (width + margin) * tag;
    btn.frame = CGRectMake(x, 0, width, jisuan(60));
    [self.headerView addSubview:btn];
    
    if (image) {
        
        [btn setImage:image forState:UIControlStateNormal];
    }
    
    if (tag == 0) {
        
        // 设置“综合”为默认选中状态
        self.selectedBtn = btn;
        btn.selected = YES;
//        self.selectedBtn.selected  = NO;
        
    }else {
        
        btn.selected = NO;
        
    }
    
    
    if (tag == 0) {
        
        // 综合
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        
    }else if (tag == 3) {
        
        // 筛选
        btn.titleEdgeInsets = UIEdgeInsetsMake(0, -btn.imageView.frame.size.width - btn.frame.size.width + btn.titleLabel.frame.size.width + jisuan(15), 0, 0);
        btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -btn.titleLabel.frame.size.width - btn.frame.size.width +  jisuan(20));
        
    }else if (tag == 2) {
        
        // 价格
        
        btn.titleEdgeInsets = UIEdgeInsetsMake(0, -btn.imageView.frame.size.width - btn.frame.size.width + btn.titleLabel.frame.size.width + jisuan(15), 0, 0);
        btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -btn.titleLabel.frame.size.width - btn.frame.size.width + jisuan(20));
        
    }
    
    
    if (tag == 2) {
        
        // 价格
        [btn setImage:[UIImage imageNamed:@"priceUp"] forState:UIControlStateSelected];
        
    }else if (tag == 3) {
        
        // 筛选
//        [btn setImage:[UIImage imageNamed:@"filterSelected"] forState:UIControlStateSelected];
        
    }
    
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    
}

#pragma mark -lazy
- (UIView *)headerV {
    
    if (!_headerV) {
        
        _headerV = [[UIView alloc] init];
        _headerV.backgroundColor = WhiteColor;
    }
    
    return _headerV;
    
}

- (UIImageView *)leftIV {
    
    if (!_leftIV) {
        
        _leftIV = [[UIImageView alloc] init];
        _leftIV.contentMode = UIViewContentModeScaleAspectFit;
        _leftIV.image = [UIImage imageNamed:@"sectionHeaderLeft"];
    }
    
    return _leftIV;
}

- (UIImageView *)rightIV {
    
    if (!_rightIV) {
        
        _rightIV = [[UIImageView alloc] init];
        _rightIV.contentMode = UIViewContentModeScaleAspectFit;
        _rightIV.image = [UIImage imageNamed:@"sectionHeaderRight"];
        
    }
    
    return _rightIV;
}

- (UILabel *)headerTitle {
    
    if (!_headerTitle) {
        
        _headerTitle = [[UILabel alloc] init];
        _headerTitle.font = [UIFont fontWithName:@"Helvetica-Bold" size:jisuan(30)];
        _headerTitle.textAlignment = NSTextAlignmentCenter;
        _headerTitle.textColor = Color333333;
        _headerTitle.text = @"热销商品";
    }
    
    return _headerTitle;
}

- (UILabel *)desL {
    
    if (!_desL) {
        
        _desL = [[UILabel alloc] init];
        _desL.textAlignment = NSTextAlignmentCenter;
        _desL.textColor = Color999999;
        _desL.font = Font(20);
        _desL.text = @"把最好的推荐给你，只有我们最懂你";
        
    }
    
    return _desL;
    
}

- (UIView *)bg {
    
    if (!_bg) {
        
        _bg = [[UIView alloc] init];
        _bg.backgroundColor = WhiteColor;

        
    }
    
    return _bg;
}

- (UIView *)headerView {
    
    if (!_headerView) {
        
        _headerView = [[UIView alloc] init];
        
        _headerView.backgroundColor = WhiteColor;
    }
    
    return _headerView;
    
}

- (UITableView *)hotGoodsTableView {
    
    if (!_hotGoodsTableView) {
        
        _hotGoodsTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        
        _hotGoodsTableView.backgroundColor = WhiteColor;
        
        _hotGoodsTableView.delegate = self;
        _hotGoodsTableView.dataSource = self;
        
        _hotGoodsTableView.showsVerticalScrollIndicator = NO;
        _hotGoodsTableView.showsHorizontalScrollIndicator = NO;
        
        _hotGoodsTableView.estimatedRowHeight = 0;
        _hotGoodsTableView.estimatedSectionFooterHeight = 0;
        _hotGoodsTableView.estimatedSectionHeaderHeight = 0;
        
        _hotGoodsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        
        [_hotGoodsTableView registerClass:[ShoppingHotContentTableViewCell class] forCellReuseIdentifier:hotGoodsCellID];
        
        
        if (@available(iOS 11.0, *)) {
            
            _hotGoodsTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        
    }
    
    return _hotGoodsTableView;
    
}

- (UIView *)loadMoreView {
    
    if (!_loadMoreView) {
        
        _loadMoreView = [[UIView alloc] init];
        _loadMoreView.backgroundColor = WhiteColor;
    }
    
    return _loadMoreView;
    
}

- (UIImageView *)smallBackIV {
    
    if (!_smallBackIV) {
        
        _smallBackIV = [[UIImageView alloc] init];
        _smallBackIV.image = [UIImage imageNamed:@"smallBackBg1"];
        _smallBackIV.contentMode = UIViewContentModeScaleAspectFit;
        
    }
    
    return _smallBackIV;
}

- (UILabel *)loadMoreL {
    
    if (!_loadMoreL) {
        
        _loadMoreL = [[UILabel alloc] init];
        _loadMoreL.backgroundColor = WhiteColor;
        
        _loadMoreL.text = @"更多商品";
        _loadMoreL.textColor = Color1f89ff;
        _loadMoreL.font = Font(20);
        _loadMoreL.textAlignment = NSTextAlignmentRight;
        
        _loadMoreL.userInteractionEnabled = YES;
        UITapGestureRecognizer *loadMoreGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(loadMoreGestureClick:)];
        [_loadMoreL addGestureRecognizer:loadMoreGesture];
        
    }
    
    return _loadMoreL;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
